<!--部门待结算明细-->
<template>
  <div>
    <f-search-form ref='search' :more='true' @searchHandler='searchHandler' @exportHandler='exportHandler' :show-export-btn='true'>
      <f-search-form-item label='订单编号' name='orderNo' />
      <f-search-form-item label='业务员' name='saleManName' />
      <f-search-form-item label='单位名称' name='customName' />
      <f-search-form-item label='部门' name='deptId' type='select' :data='api.hyorder.listByCompanyId' :params='queryParam' value-key='deptId' label-key='deptName' slot='advanced' />
      <f-search-form-item label='发货日期' type='range' name='beginDate' slot='advanced' />
    </f-search-form>
    <f-table ref='table' rowKey='orderDetailsReturnId' 
             :showSetting='false' 
             setting-key='dept_settle_tab1' 
             :tableColumns='columns' 
             :scroll='{x:true}' 
             handler='hyDeptSettleApplyTab1PageListHandler' 
             :showMultipleBtn='false' 
             :operator='operator' 
             :multiple='multiple' 
             :params='queryParam' 
             :api='api.hyOrderDetailsReturn'>
       <span slot='sendType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text==1'>现款</a-tag>
            <a-tag color='#FF0000' v-if='text==2'>预收款</a-tag>
            <a-tag color='#87d068' v-if='text==3'>资保金</a-tag>
            <a-tag color='purple' v-if='text==4'>全额资信</a-tag>
       </span>
      <span slot='saleType' slot-scope='text, record, index'>
           <a-tag color='#2db7f5' v-if='text=="CHA"'>销售</a-tag>
           <a-tag color='#FF0000' v-if='text=="CHC"'>退货</a-tag>
           <a-tag color='purple' v-if='text==4'>票折</a-tag>
       </span>
      <span slot='deptType' slot-scope='text, record, index'>
        <a-tag color='#87d068' v-if='text=="ZS"'>招商</a-tag>
        <a-tag color='#108ee9' v-if='text=="ZY"'>自营</a-tag>
      </span>
      <span slot='action' slot-scope='text, record'>
          <template>
            <a @click='$refs.orderDetailsDrawer.showDrawer(record)'>查看</a>
          </template>
        </span>
    </f-table>
    <settle-apply-drawer ref='settleApplyDrawer' @success='onLoad'></settle-apply-drawer>
    <hy-order-details-drawer ref='orderDetailsDrawer'></hy-order-details-drawer>
  </div>
</template>
<script>
import api from "../../../js/api"
import SettleApplyDrawer from "./components/settle_apply_drawer"
import HyOrderDetailsDrawer from "@/views/module/haiying/order/details/hyorder_details_drawer"

export default {
  name: "Tab1",
  components: { HyOrderDetailsDrawer, SettleApplyDrawer },
  data() {
    let me = this
    //操作按钮
    let operator = []
    //是否是商务角色
    let isSw = this.$store.state.user.roleInfo.isSw
    operator.push({
      name: "申请结算",
      that: this,
      handler: (table, that) => {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          this.$refs.settleApplyDrawer.showDrawer({
            selectIds: selectIds.join(",")
          })
        } else {
          that.$message.error("请选择结算数据")
        }
      }
    })
    return {
      api: Object.assign(api, this.api),
      multiple: true,
      deptId: "",
      //列表初始化查询参数
      queryParam: {
        fileName: "待结算数据明细",
        auth: 1,
        isFlp: 1
      },
      returnCustomBond: 0,
      selectIds: "",
      params1: {
        deptId: ""
      },
      columns: [
        {
          title: "序号",
          width: "60px",
          align: "center",
          fixed: "left",
          dataIndex: "rowIndex",
          customRender: function(text, record, index) {
            return (record.rowIndex !== "合计") ? (parseInt(index) + 1) : record.rowIndex
          }
        },
        {
          title: "发货日期",
          align: "center",
          fixed: "left",
          width: "100px",
          dataIndex: "sendDate"
        },
        {
          title: "订单编号",
          align: "center",
          fixed: "left",
          dataIndex: "orderNo"
        },
        {
          title: "发货单号",
          align: "center",
          fixed: "left",
          dataIndex: "outOrderNo"
        },
        {
          title: "部门名称",
          align: "left",
          sorter:true,
          width: "100px",
          dataIndex: "deptName"
        },
        {
          title: "业务员",
          align: "left",
          width: "100px",
          sorter:true,
          dataIndex: "saleManName"
        },
        {
          title: "业务员编码",
          align: "left",
          width: "100px",
          sorter:true,
          dataIndex: "businessCode"
        },
        {
          title: "销售类型",
          align: "center",
          width: "80px",
          dataIndex: "saleType",
          scopedSlots: { customRender: "saleType" }
        },
        {
          title: "业务类型",
          align: "center",
          width: "80px",
          dataIndex: "deptType",
          scopedSlots: { customRender: "deptType" }
        },
        {
          title: "发货方式",
          align: "center",
          width: "100px",
          dataIndex: "sendType",
          scopedSlots: { customRender: "sendType" }
        },
        {
          title: "单位名称",
          align: "left",
          width: "130px",
          sorter:true,
          ellipsis: true,
          dataIndex: "customName"
        },
        {
          title: "商品名称",
          align: "left",
          sorter:true,
          ellipsis: true,
          width: "140px",
          dataIndex: "drugsName"
        },
        {
          title: "规格",
          align: "left",
          width: "80px",
          dataIndex: "drugsSpec"
        },
        {
          title: "批号",
          align: "left",
          width: "80px",
          dataIndex: "drugLotNo"
        },
        {
          title: "销售单价",
          align: "center",
          width: "80px",
          type: 10,
          dataIndex: "salePrice"
        },
        {
          title: "数量",
          align: "center",
          width: "80px",
          type: 10,
          dataIndex: "saleNum"
        },
        {
          title: "含税金额",
          align: "center",
          width: "80px",
          type: 10,
          dataIndex: "saleAmount"
        },
       
        {
          title: "回款金额",
          align: "center",
          type: 10,
          width: "80px",
          dataIndex: "returnAmount"
        },
        {
          title: "回款日期",
          align: "center",
          width: "120px",
          dataIndex: "returnDate"
        },
        {
          title: "回款银行",
          align: "center",
          width: "80px",
          dataIndex: "returnBank"
        },
        {
          title: "部门利润",
          align: "center",
          width: "100px",
          type: 10,
          dataIndex: "deptProfitAmount"
        },
        {
          title: "结算标准",
          align: "center",
          width: "100px",
          fixed: "right",
          type: 10,
          dataIndex: "deptRate"
        },
        {
          title: "部门结算价",
          align: "center",
          fixed: "right",
          width: "90px",
          type: 10,
          dataIndex: "deptPrice"
        },
        {
          title: "部门结算金额",
          align: "center",
          width: "100px",
          needTotal: true,
          fixed: "right",
          type: 10,
          dataIndex: "deptSettleAmount"
        },
        {
          title: "操作",
          align: "center",
          width: "80px",
          dataIndex: "action",
          fixed: "right",
          scopedSlots: { customRender: "action" }
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    renderTdBackground(record, flag) {
      if (record.settleApplyId) {
        return {
          style: {
            "background-color": "rgb(255,150,150)",
            "text-decoration": "line-through"
          }
        }
      }
    },
    setData() {
    },
    //部门切换
    deptChange(value) {
      this.queryParam.deptId = value
      //this.openMultiple()
      this.$refs.saleMan.initData(this.queryParam)
      this.$refs.table.refresh(true, this.queryParam)
      this.$forceUpdate()
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },

    openMultiple() {
      if (this.queryParam.deptId) {
        this.multiple = true
        this.$refs.table.openMultiple()
      } else {
        this.multiple = false
        this.$refs.table.closeMultiple()
      }
    },
    /**
     * 刷新列表
     */
    onLoad() {
      this.$refs.table.refresh()
      this.$emit("changeTab")
    }
  }
}
</script>